package role

import (
	"context"
	"fast-boot/app/api/admin/internal/svc"
	"fast-boot/app/api/admin/internal/types"
	"fast-boot/app/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type MenuIdsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取角色的菜单ID集合
func NewMenuIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenuIdsLogic {
	return &MenuIdsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MenuIdsLogic) MenuIds(req *types.SysMenuIdReq) (resp []int64, err error) {

	rmModel := model.SysRoleMenuModel{}
	menuIds := make([]int64, 0)
	l.svcCtx.GormClient.GormDb.Model(rmModel).
		Where("role_id = ?", req.Id).
		Pluck("menu_id", &menuIds)

	return menuIds, nil
}
